package com.bean;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import java.util.Date;

/** User实体类对应数据库表，并且使用后端JRS-303校验，避免有人恶意绕过前端格式校验（禁用某些js代码），进行注册等操作
 * @author WxrStart
 * @create 2022-05-17 16:54
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class User {
    @TableId(type= IdType.AUTO)
    private Integer userId;
    private String nickName;
    @Pattern(regexp ="^[a-z\\d]+(\\.[a-z\\d]+)*@([\\da-z](-[\\da-z])?)+(\\.{1,2}[a-z]+)+$" ,message = "必须为合法的邮箱地址")
    private String email;
    @Pattern(regexp = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,15}$",message = "密码必须由数字、字母两种字符组成,长度在8-15位之间")
    private String password;
    @Pattern(regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$",message = "必须为合法的手机号")
    private String phone;
    private String picture;
    private Integer status;
    private String userRole;
    private String address;
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;
    private String salt;

    public User(Integer userId, @Email(message = "必须为合法的邮箱地址") String email, @Pattern(regexp = "/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,15}$/ ", message = "密码必须由数字、字母两种字符组成,长度在8-15位之间") String password) {
        this.userId = userId;
        this.email = email;
        this.password = password;
    }

    public User(@Email(message = "必须为合法的邮箱地址") String email, @Pattern(regexp = "/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,15}$/ ", message = "密码必须由数字、字母两种字符组成,长度在8-15位之间") String password) {
        this.email = email;
        this.password = password;
    }
}
